package com.ibeeking.found.upms.b.rest.controller.v1;

import com.ibeeking.found.upms.b.rest.service.IShopRoleService;
import com.ibeeking.found.upms.service.common.param.RolePermissionParam;
import com.ibeeking.found.upms.service.common.param.ShopRoleParam;
import com.ibeeking.found.upms.service.common.query.ShopRolePageQuery;
import com.ibeeking.found.upms.service.common.vo.ShopRolePageVO;
import com.ibeeking.found.upms.service.common.vo.ShopRoleVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @ClassName OriginalShopRoleController控制器
 * @Description 初始角色管理
 * @Author ibeeking
 * @Date 2020-12-02 15:29
 **/
@RestController
@RequestMapping("/b/originalRole/v1")
public class ShopRoleController {

    @Resource
    private IShopRoleService shopRoleServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询商户角色列表")
    @PostMapping(value = "/pageList")
    public Page<ShopRolePageVO> pageList(@RequestBody @Validated ShopRolePageQuery query) {
        return shopRoleServiceImpl.pageList(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "新增商户角色")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) ShopRoleParam param) {
        return shopRoleServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改商户角色")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) ShopRoleParam param) {
        return shopRoleServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询商户角色")
    @GetMapping(value = "/view/{id}")
    public ShopRoleVO view(@PathVariable("id") Long id) {
        return shopRoleServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "启用/禁用商户角色")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return shopRoleServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除商户角色")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return shopRoleServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "通过商户角色Id修改角色权限信息")
    @PostMapping(value = "/modifyByRoleId")
    public Boolean modifyByRoleId(@RequestBody @Validated RolePermissionParam param) {
        return shopRoleServiceImpl.modifyRolePermissionByRoleId(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "根据角色查询权限id列表")
    @GetMapping(value = "/queryPermissionIdsByRoleId/{roleId}")
    public List<String> queryPermissionIdsByRoleId(@PathVariable("roleId") @NotNull(message = "roleId不能为空") Long roleId) {
        return shopRoleServiceImpl.queryPermissionIdsByRoleId(roleId);
    }
}
